// pages/goods/index.js
var api = require('../../utils/api.js')
var app = new getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navH: 0,
    isIphoneX: false,
    label:['背景墙','地面','墙面','桌台面','橱柜面板','其他'],
    content:null,
    ishow:false,
    search:"",
    activeIndex: "",
    //排序
    sortListArr:[0,0,0]
  },
  select(e){
    let value = e.detail.value
    this.setData({
      search:value
    })
    this.search()
  },
  changeSort(e){
    let id = e.currentTarget.dataset.id
    this.setData({
      activeIndex: id
    })
    this.search()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //产品
    this.setData({
      activeIndex:options.id
    })
    this.getData()
    this.getCountHeight()
  },
  getCountHeight(){
    let isIphoneX = app.globalData.isIphoneX
    if (isIphoneX) {
      this.setData({
        isIphoneX
      })
    }
    this.setData({
      navH: app.globalData.navHeight
    })
  },
  getData(){
    let params = {
      page:1,
      size:999,
      space_id:this.data.activeIndex,
      member_id:api.cache('user').member_id||""
    }
    api.post('soft_goods_info',params).then(res => {
      if (res.code == 200) {
        this.setData({
          content: res.data
        })
      }
    })
  },
  changeShow(){
    this.setData({
      ishow:!this.data.ishow
    })
  },
  toDetail(e){
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/goods/detail/detail?id=${id}&type=1`,
    })
  },
  search() {
    let data = this.data;
    let condition = data.search
    let space_id = data.activeIndex
    let params = {
      page:1,
      size:999,
      space_id,
      member_id:api.cache('user').member_id||"",
      condition
    }
    api.post('soft_goods_search',params).then(res => {
      if (res.code == 200) {
        let content = this.data.content
        content.goods_arr = res.data.goods_arr
        this.setData({
          content
        })
      }
    })
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      // imageUrl: '../../imgs/index/share.jpg',
      // title: app.globalData.shareTitle,
      // path: '/pages/index/index'
    }
  }
})